include( "shared.lua" )
include( 'sh_player.lua' )
require("datastream")

/*-------------------------
Class Changer menu
-------------------------*/
local ClassMenu = nil

function GM:ShowClassChooser( pl )
	if ( !IsValid( ClassMenu ) ) then
		ClassMenu = vgui.CreateFromTable( vgui_Splash )
		ClassMenu:SetHeaderText( "Class Selection" )
		ClassMenu:SetHoverText( "Select a class to play." )
		
		local function1 = function()
			RunConsoleCommand("p_classswap","shotgunner")
		end
		
		local function2 = function()
			RunConsoleCommand("p_classswap","gunner")
		end
		
		local Button = ClassMenu:AddSelectButton( "Shotgunner", function1 )
		Button.m_colBackground = Color(255, 90, 90, 255) 
		
		local Button2 = ClassMenu:AddSelectButton( "Gunner", function2 )
		Button2.m_colBackground = Color(255, 90, 90, 255)

		ClassMenu:AddCancelButton()
	end
 
	ClassMenu:MakePopup()
end

function distance(p1, p2)
	local v = p2 - p1
	return math.floor(math.sqrt( v.x*v.x + v.y*v.y + v.z*v.z ))
end

/*-------------------------
hud
-------------------------*/ 
function myhud()
local client = LocalPlayer()

if not client:Alive() then return end
if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end

local player_health = client:Health()
local Player_armor = client:Armor()
local player_class = client:GetPlayerClass()

local player_money = client:GetMoney()
local player_loot = client:GetLoot()

local weapon_mag = client:GetActiveWeapon():Clip1() -- How much ammunition you have inside the current magazine
local weapon_reserve = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) -- How much ammunition you have outside the current magazine
local weapon_secondary = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) -- How much ammunition you have for you

local game_round = (GetGlobalInt( "RoundNumber", 0 ) + 1)
local game_timer = (string.ToMinutesSeconds(GAMEMODE:GetGameTimeLeft()))

--Health
draw.RoundedBox(0,3, ScrH() - 53, 60, 50, Color(0, 0, 0, 180))
draw.SimpleText("Health", "Trebuchet19", 12, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(player_health), "HUDNumber", 32, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--armor
draw.RoundedBox(0,66, ScrH() - 53, 60, 50, Color(0, 0, 0, 180))
draw.SimpleText("Armor", "Trebuchet19", 76, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(Player_armor), "HUDNumber", 95, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--dosh
draw.RoundedBox(0,3, ScrH() - 87, 123, 31 , Color(0, 0, 0, 180))
draw.SimpleText("$", "HUDNumber",5, ScrH() - 52, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(player_money), "HUDNumber",124, ScrH() - 52, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM)

--backpack
draw.RoundedBox(0,3, ScrH() - 121, 123, 31 , Color(34, 84, 34, 180))
draw.SimpleText("+", "HUDNumber",5, ScrH() - 85, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(player_loot), "HUDNumber",124, ScrH() - 85, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM)

--reserve
draw.RoundedBox(0,ScrW() - 63, ScrH() - 53, 60, 50 , Color(0, 0, 0, 180))
draw.SimpleText("Reserve", "Trebuchet19", ScrW() - 59, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(weapon_reserve), "HUDNumber", ScrW() - 33, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--ammo
draw.RoundedBox(0,ScrW() - 126, ScrH() - 53, 60, 50 , Color(0, 0, 0, 180))
draw.SimpleText("ammo", "Trebuchet19", ScrW() - 116, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(weapon_mag), "HUDNumber", ScrW() - 96, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--class
draw.SimpleText(tostring(player_class.DisplayName), "Trebuchet19",ScrW() - 3, ScrH() - 54, Color(255, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM)

--round number
draw.RoundedBox(0,ScrW() / 2 - 63, ScrH() - 53, 60, 50 , Color(0, 0, 0, 180))
draw.SimpleText("Round", "Trebuchet19", ScrW() / 2 - 53, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(game_round), "HUDNumber", ScrW() / 2 - 33, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--round timer
draw.RoundedBox(0,ScrW() / 2, ScrH() - 53, 90, 50 , Color(0, 0, 0, 180))
draw.SimpleText("Timer", "Trebuchet19", ScrW() / 2 + 25, ScrH() - 4, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(tostring(game_timer), "HUDNumber", ScrW() / 2 + 45, ScrH() - 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)

--show dosh factories
	for k,v in pairs ( ents.FindByClass("ent_pi_factory_dosh") ) do

		local Position = ( v:GetPos() + Vector( 0,0,60 ) ):ToScreen()
		local Distance = 0
		 
		if v == Entity() then
				Distance = 0 
			else
				local ent = v:GetLocalPos()
				local ply = LocalPlayer():GetLocalPos()
				Distance = distance(ent, ply)
		end
			if(Distance < 600)then
				draw.DrawText("Take my money!", "TargetIDSmall", Position.x, Position.y, Color( 255, 255, 255, 255 ), 1 )
			end
	end
end

hook.Add("HUDPaint", "myhud", myhud)

local tohide = { -- This is a table where the keys are the HUD items to hide
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) -- This is a local function because all functions should be local unless another file needs to run it
	if (tohide[name]) then     -- If the HUD name is a key in the table
		return false;      -- Return false.
	end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)

/*-------------------------
PushNotify
-------------------------*/
local function GPush_Notify( data )
	local message = data:ReadString() 
	local time = data:ReadLong() 
	notification.AddLegacy(message, NOTIFY_GENERIC, time)
	surface.PlaySound("buttons/button15.wav") 
end
usermessage.Hook( "GPush_Notify", GPush_Notify );